package com.rabbiter.oes.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.rabbiter.oes.entity.Admin;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface AdminMapper extends BaseMapper<Admin> {

    /**
     * 查询全部管理员信息
     * @return
     */
    default List<Admin> findAll() {
        return selectList(new QueryWrapper<>());
    }


    default Admin selectByAccAndPwd(String acc) {
        LambdaQueryWrapper<Admin> adminWrapper = Wrappers.lambdaQuery(Admin.class);
        adminWrapper.eq(Admin::getAcc, acc);
        return selectOne(adminWrapper);
    }

    /**
     * 根据id修改密码
     * @param id
     * @param pwd
     * @return
     */
    default int updatePwdById(Integer id, String pwd) {
        Wrapper<Admin> updateWrapper = Wrappers.lambdaUpdate(Admin.class).eq(Admin::getId, id).set(Admin::getPwd, pwd);
        return update(new Admin(), updateWrapper);
    }

}
